package com.anzia.reader;

import java.io.FileReader;
import java.io.IOException;

/**
 *@ClassName FileReader_Demo
 *@Description
 *@Author Anzia.
 *@Date 2021/4/9 15:45
 *@Version 1.0
 **/
public class FileReader_Demo {

    public static void main(String[] args) throws Exception {

        //创建FileReader 文件字符输入流
        FileReader fr = new FileReader("static\\hello.txt");
        FileReader_Demo demo = new FileReader_Demo();

        //读取
        //demo.single_read(fr);
        demo.more_read(fr);

        //关闭
        fr.close();
        System.out.println();
        System.out.println("执行完毕！");

    }

    public void single_read(FileReader fr) throws IOException {

        int data = 0;
        while ((data = fr.read()) != -1) {
            System.out.print((char) data);
        }

    }

    public void more_read(FileReader fr) throws IOException {

        char[] chars = new char[2];
        int count = 0;
        while ((count = fr.read(chars)) != -1) {
            System.out.println(new String(chars, 0, count));
        }

    }

}
